<?php
define('POPUP_STYLE_WIN'	,	'WIN');
define('POPUP_STYLE_LAYER'	,	'LAYER');
class Cl_Popup extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$popup_seq			= 0					,	//	
		$popup_title		= ''				,	//	
		$popup_content		= ''				,	//	
		$popup_style		= POPUP_STYLE_LAYER	,	//	
		$popup_pos_x		= 0					,	//	
		$popup_pos_y		= 0					,	//	
		$popup_width		= 0					,	//	
		$popup_height		= 0					,	//	
		$popup_start		= 0					,	//	
		$popup_end			= 0					,	//	
		$popup_use_flag		= 'T'				,	//	
		$popup_close_flag	= 'F'				,	//	
		$popup_insert_time	= 0					,	//	
		$popup_del_flag		= 'F'				;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($popup_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($popup_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		$this->popup_start_date = date('Y-m-d', $this->popup_start);
		$this->popup_start_hour = date('H', $this->popup_start);
		$this->popup_start_min	= date('i', $this->popup_start);
		$this->popup_end_date	= date('Y-m-d', $this->popup_end);
		$this->popup_end_hour	= date('H', $this->popup_end);
		$this->popup_end_min	= date('I', $this->popup_end);		
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->popup_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$this->popup_hits		= 0;
		$this->popup_insert_time	= time();
		$this->popup_del_flag		= 'F';
		
		$data = array(	'popup_title'		=>	$this->popup_title,
						'popup_content'		=>	$this->popup_content,
						'popup_style'		=>	$this->popup_style,
						'popup_pos_x'		=>	$this->popup_pos_x,
						'popup_pos_y'		=>	$this->popup_pos_y,
						'popup_width'		=>	$this->popup_width,
						'popup_height'		=>	$this->popup_height,
						'popup_start'		=>	$this->popup_start,
						'popup_end'			=>	$this->popup_end,
						'popup_use_flag'	=>	$this->popup_use_flag,
						'popup_close_flag'	=>	$this->popup_close_flag,
						'popup_insert_time'	=>	$this->popup_insert_time,
						'popup_del_flag'	=>	$this->popup_del_flag
					);
		$this->popup_seq = $dbo->insert($data);
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/

		$data = array(	'popup_title'		=>	$this->popup_title,
						'popup_content'		=>	$this->popup_content,
						'popup_style'		=>	$this->popup_style,
						'popup_pos_x'		=>	$this->popup_pos_x,
						'popup_pos_y'		=>	$this->popup_pos_y,
						'popup_width'		=>	$this->popup_width,
						'popup_height'		=>	$this->popup_height,
						'popup_start'		=>	$this->popup_start,
						'popup_end'			=>	$this->popup_end,
						'popup_use_flag'	=>	$this->popup_use_flag,
						'popup_close_flag'	=>	$this->popup_close_flag
					);
		$dbo->update($data, array("popup_seq = ".$this->popup_seq));
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("popup_seq = ".$this->popup_seq));
		$this->backup($log);
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
// 		/*------------------------------------------------------------*/
// 		$dbo = self::getDbo();
// 		/*------------------------------------------------------------*/
// 		$dbo->log($this->user_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}